﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

class AtkState : Istate
{
    
    enemy parent;
    public void enter(enemy parent)
    {
        this.parent = parent;
    }

    public void exit()
    {
      
    }

    public void update()
    {
        if (!parent.IsAttacking)
        {
            parent.StartCoroutine(attack());
        }
        
        float distance = Vector2.Distance(parent.transform.position, parent.MyTrgt.transform.position);
        if (parent.MyTrgt !=null)
        {
            if (distance > parent.AtkRange)
            {
                parent.changeState(new MoveState());
            }

        }
        else
        {
            parent.changeState(new IdleState());
        }
    }
    public IEnumerator attack()
    {
        parent.IsAttacking = true;
        parent.MyAnimator.SetTrigger("atk");
        parent.Attack();
        yield return new WaitForSeconds(parent.MyAnimator.GetCurrentAnimatorStateInfo(2).length);
        parent.IsAttacking = false;
    }
}

